package com.trade.dao.util;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.text.*;

import com.trade.data.HistoricalDataVO;
import com.trade.data.EquityIntradayDataVO;
import com.trade.data.type.MovingAveragePeriodTypes;
import com.trade.data.calculation.MovingAverageValuesVO;

import com.trade.data.type.*;

import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;

public class CandleStickPatternUtil {

	public static CandleStickPatterns getPattern(List<EquityIntradayDataVO> historicalDataVOList ){

		EquityIntradayDataVO currentEquity = historicalDataVOList.size() > 0 ? historicalDataVOList.get(historicalDataVOList.size() - 1) : null ;
		EquityIntradayDataVO previousEquity1 = historicalDataVOList.size() > 1 ? historicalDataVOList.get(historicalDataVOList.size() - 2) : null ;
		EquityIntradayDataVO previousEquity2 = historicalDataVOList.size() > 2 ? historicalDataVOList.get(historicalDataVOList.size() - 3) : null ;
		EquityIntradayDataVO previousEquity3 = historicalDataVOList.size() > 3 ? historicalDataVOList.get(historicalDataVOList.size() - 4) : null ;
		EquityIntradayDataVO previousEquity4 = historicalDataVOList.size() > 4 ? historicalDataVOList.get(historicalDataVOList.size() - 5) : null ;

		if( currentEquity.getOpen() < currentEquity.getHigh() && currentEquity.getClose() > currentEquity.getLow() && currentEquity.getClose() < currentEquity.getOpen())
		{
			return CandleStickPatterns.BIG_BLACK_CANDLE;
		}
		if( currentEquity.getOpen() > currentEquity.getLow() && currentEquity.getClose() < currentEquity.getHigh() && currentEquity.getClose() > currentEquity.getOpen())
		{
			return CandleStickPatterns.BIG_WHITE_CANDLE;
		}
		if( currentEquity.getOpen().intValue() == currentEquity.getClose().intValue()
				&& currentEquity.getOpen() < currentEquity.getHigh()
				&& currentEquity.getClose() < currentEquity.getHigh()
				&& currentEquity.getOpen() > currentEquity.getLow()
				&& currentEquity.getClose() > currentEquity.getLow()
		)
		{
			return CandleStickPatterns.DOJI;
		}

		if( currentEquity.getClose().intValue() == currentEquity.getHigh().intValue()
			&& currentEquity.getOpen().intValue() == currentEquity.getHigh().intValue()
			&& currentEquity.getClose() > currentEquity.getLow()
		)
		{
			return CandleStickPatterns.DRAGON_FLY_DOJI;
		}


		if( currentEquity.getClose().intValue() == currentEquity.getLow().intValue()
			&& currentEquity.getOpen().intValue() == currentEquity.getLow().intValue()
			&& currentEquity.getClose() < currentEquity.getHigh()
		)
		{
			return CandleStickPatterns.GRAVESTONE_FLY_DOJI;
		}


		return null;
	}

}
